import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:local_task/common/tools/extensions.dart';
import 'package:local_task/controller/intro_controller.dart';

/// 引导页
class Intro extends StatelessWidget {
  Intro({Key? key}) : super(key: key);

  final IntroController introController = Get.put(IntroController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Center(
        child: Column(
          children: [
            // 图片、文字
            Expanded(
                flex: 8,
                child: PageView.builder(
                  controller: introController.pageController,
                  onPageChanged: introController.currentIndex,
                  itemCount: introController.contents.length,
                  itemBuilder: (context, index) {
                    return Padding(
                      padding: const EdgeInsets.all(25.0),
                      child: Column(
                        children: [
                          Expanded(
                            flex: 8,
                            child: Image(
                              image: AssetImage(
                                  introController.contents[index].imageName ??
                                      ""),
                              // fit: BoxFit.cover,
                            ),
                          ),
                          Expanded(
                            flex: 2,
                            child: ListTile(
                              title: Text(
                                  textAlign: TextAlign.center,
                                  introController.contents[index].title ??
                                      ""),
                              subtitle: Text(
                                  textAlign: TextAlign.center,
                                  introController
                                      .contents[index].description ??
                                      ""),
                            ),
                          ),
                        ],
                      ),
                    );
                  },
                )),
            // 生成三个点。
            Expanded(
              flex: 1,
              child: SizedBox(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children:
                  List.generate(introController.contents.length, (index) {
                    return Obx(() {
                      return Container(
                        height: 15,
                        width: introController.currentIndex.value == index
                            ? 55
                            : 30,
                        margin: const EdgeInsets.only(right: 5),
                        decoration: BoxDecoration(
                          boxShadow: const [
                            BoxShadow(
                              color: Colors.black45,
                              blurRadius: 7,
                            )
                          ],
                          borderRadius: BorderRadius.circular(20),
                          color: introController.currentIndex.value == index
                              ? Theme.of(context).primaryColor
                              : Colors.white,
                        ),
                      );
                    });
                  }),
                ),
              ),
            ),
            // 下一步按钮
            Expanded(
                flex: 1,
                child: Obx(() {
                  return Container(
                    width: 60.0.wp,
                    padding: const EdgeInsets.only(top: 10, bottom: 10),
                    child: ElevatedButton(
                        onPressed: () {
                          introController.actionButton();
                        },
                        style: const ButtonStyle(alignment: Alignment.center),
                        child: Text(
                          introController.currentIndex.value ==
                              introController.contents.length - 1
                              ? "继续"
                              : "下一步",
                        )),
                  );
                }))
          ],
        ),
      ),
    );
  }
}
